﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestConsoleApp
{
    public class TestLinkConstruct
    {

        #region 链式构造
        public TestLinkConstruct() { }

        public TestLinkConstruct IsEmpty(object obj, string paramName)
        {
            if (obj == null)
            {
                throw new Exception($"参数不能为空: {paramName}为空！");
            }


            return this;//关键点
        }


        public TestLinkConstruct show()
        {


            return this;//关键点
        }
        #endregion

        #region Builder设计模式
        private String _name;
        private int _maxTotal;

        public TestLinkConstruct(String name, int maxTotal)
        {
            _name = name;
            _maxTotal = maxTotal;
        }

        class Builder
        {

            private String _name;
            private int _maxTotal;

            public Builder SetName(string name)
            {
                _name = name;
                return this;
            }
            public Builder SetMaxTotal(int maxTotal)
            {
                _maxTotal = maxTotal;
                return this;

            }

            public TestLinkConstruct build()
            {
                return new TestLinkConstruct(_name, _maxTotal);
            }

        } 
        #endregion

        public static void Test()
        {
            new TestLinkConstruct()
                .IsEmpty(null, "sdf")
                .show();

            TestLinkConstruct temp = new TestLinkConstruct.Builder().SetName("name").SetMaxTotal(1).build();
        }
    }
}
